<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>YY招聘网</title>
	<!-- 导入jquery文件s -->
	<script type="text/javascript" src="../jquery/jquery-1.11.3.js"></script>
	<!--导入jquery alert文件-->
	<script type="text/javascript" src="../jquery/alert/jquery.alerts.js"></script>
	<!--jquery信息提示样式-->
	<link rel="stylesheet" type="text/css" href="../jquery/alert/jquery.alerts.css">
	<script type="text/javascript" src="../jquery/form/jquery.form.js"></script>
	<link rel="stylesheet" href="../CSS/UserLogin.css">
</head>
<body onload="autoSetLoginInfo()">
	<div id="Header">
		<div class="Header-Logo">
			<a href="http://www.baidu.com">
				<img src="../images/yy.png" alt="YY招聘网">
			</a>
			<span class="Header-Logo-Right">
				<a href="http://localhost:8080/jsp/system/UserRegister.html">用户注册</a>
				
			</span>
			<span class="Header-Logo-Right">
				<a href="http://localhost:8080/jsp/system/CompanyRegister.html">企业注册</a>
			</span>
		</div>
	</div>
	<div id="login">
		<div class="loginTitle">
			<a href="javascript:userOn()" >
				<span class="spans">用户登录</span>
			</a >
			<a href="javascript:comOn()" >
				<span class="spans">企业登录</span>
			</a>
		</div>
		<div class="loginBody">
		
			<div class="loginBodyUl" style="display: ;" id="login1">
				<form id="opForm">
					<ul >
						<li>
							<input type="text" class="loginText" name="userDTO.userLoginName" id="userDTO.userLoginName" value="登陆账号" onblur="if(this.value==''){this.value='登陆账号'};GetPwdAndChk()"
							onfocus="if(this.value='登陆账号'){this.value=''}"></input>
						</li>
						<li>
							<input class="inputBottom" type="text" id="userShowPwd" value="登陆密码" onfocus="$.changeTip(this);"></input>
							<input class="inputBottom" style="display:none;" type="password" name="userDTO.userPwd" id="userLoginPwd" onblur="$.changeTip(this)" value=""></input>

						</li>
					</ul>
					<div class="remberMe">
						<div class="forget">
							<input id="checkBoxOne" check="checkd" type="checkbox" onclick="check2()"/>
							<span>记住我</span>
						</div>
					</div>
					<div class="submitButton" >
						<a id="submitbutton" href="javascript:SetPwdAndChk(this.form);"  >
							<span>用户&nbsp;&nbsp;登录</span>
						</a>
					</div>
				</form>

			</div>
			
			<div class="loginBodyUl" style="display:none;" id="login2">
				<form id="opForm2">
					<ul >
						<li>
							<input type="text" class="loginText" name="companyDTO.companyManName" id="userDTO.companyManName" value="登陆账号" onblur="if(this.value==''){this.value='登陆账号'};"
							onfocus="if(this.value='登陆账号'){this.value=''}"></input>
						</li>
						<li>
							<input class="inputBottom" type="text" id="userShowPwd2" value="登陆密码" onfocus="$.changeTip2(this);"></input>
							<input class="inputBottom" style="display:none;" type="password" name="companyDTO.companyManPwd" id="truePwd" onblur="$.changeTip2(this)" value=""></input>

						</li>
					</ul>
					<div class="remberMe">
						<div class="forget">
							<input id="checkBoxOne" check="checkd" type="checkbox" onclick="check2()"/>
							<span>记住我</span>
						</div>
					</div>
					<div class="submitButton" style="background: purple;">
						<a id="submitbutton" href="javascript:SetPwdAndChk2(this.form);" style="background: purple;">
							<span>企业&nbsp;&nbsp;登录</span>
						</a>
					</div>
				</form>

			</div>	
			
			
			<div class="final">
				<span style="font-family: 幼圆; font-size: 14px; font-weight: bold; color: gray;">
					版权所有 © 2014-2015 YY招聘网
				</span>
			</div>
		</div>
	</div>

	<script type="text/javascript">
		function autoSetLoginInfo(){
			if(isPostBack == "False"){
				//第一次加载要执行想东西
				GetLastUser();
			}
		}
		function GetLastUser() 
		{ 
		var id = "49BAC005-7D5B-4231-8CEA-16939BEACD67"; 
		var usr = GetCookie(id); 
		if(usr != null) 
		{ 
		document.getElementById('userLoginName').value = usr; 
		} 
		else 
		{ 
		document.getElementById('userLoginName').value = "001"; 
		} 
		GetPwdAndChk(); 
		} 
		function SetPwdAndChk(){
			var usr = document.getElementById('userDTO.userLoginName').value; 
			//将最后一个用户信息写入cookie
			SetLastUser(usr); 
			if(document.getElementById('checkBoxOne').checked == true){
				var pwd = document.getElementById('userLoginPwd').value;
				var expdate = new Date(); 
				expdate.setTime(expdate.getTime() + 14 * (24 * 60 * 60 * 1000)); 
				//将用户名和密码写入到Cookie 
				SetCookie(usr,pwd, expdate); 
			}
			else{
				//如果没有选中记住密码,则立即过期 
				ResetCookie(); 
			}
			$.loginCheck()
			//window.location.href="http://localhost:8080/jsp/system/userIndex.html"; 
		}
		
		function ResetCookie() 
		{ 
		var usr = document.getElementById('userDTO.userLoginName').value; 
		var expdate = new Date(); 
		SetCookie(usr, null, expdate); 
		} 
		
		function SetLastUser(usr){
			var id = "49BAC005-7D5B-4231-8CEA-16939BEACD67"; 
			var expdate = new Date(); 
			//当前时间加上两周的时间 
			expdate.setTime(expdate.getTime() + 14 * (24 * 60 * 60 * 1000)); 
			SetCookie(id, usr, expdate); 
		}
		//写入cookie
		function SetCookie(name, value, expires) 
		{ 
		var argv = SetCookie.arguments; 
		//本例中length = 3 
		var argc = SetCookie.arguments.length; 
		var expires = (argc > 2) ? argv[2] : null; 
		var path = (argc > 3) ? argv[3] : null; 
		var domain = (argc > 4) ? argv[4] : null; 
		var secure = (argc > 5) ? argv[5] : false; 
		document.cookie = name + "=" + escape (value) + 
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
		((path == null) ? "" : ("; path=" + path)) + 
		((domain == null) ? "" : ("; domain=" + domain)) + 
		((secure == true) ? "; secure" : ""); 
		}
		//用户失去焦点时调用那个该方法
		function GetPwdAndChk(){
			var user = document.getElementById('userDTO.userLoginName').value;
			var pwd = GetCookie(user);
			if(pwd != null){
				document.getElementById('checkBoxOne').checked = true; 
				document.getElementById('userLoginPwd').value = pwd; 
			}
			else{
				document.getElementById('checkBoxOne').checked = false; 
				document.getElementById('userLoginPwd').value = ""; 
			}
		}
		
		//通过输入的用户名从已经有的cookie中获取该用户的密码
		function GetCookie(name){
			var arg = name + "="; 
			var alen = arg.length;
			var clen = document.cookie.length;
			var i = 0;
			while(i < clen){
				var j = i + alen;
				if(document.cookie.substring(i,j) == arg)
					return getCookieVal(j);
				i = document.cookie.indexOf(" ", i) + 1; 
				if(i == 0)
					break;
			}
			return null;
		}
		//判断页面是否第一次加载
		var isPostBack = "<%= IsPostBack %>"; 
		
		function getCookieVal (offset) 
		{ 
		var endstr = document.cookie.indexOf (";", offset); 
		if (endstr == -1) 
		endstr = document.cookie.length; 
		return unescape(document.cookie.substring(offset, endstr)); 
		} 
		
		
		
		
		
		function getCookie(cookie_name) {
			var allcookies = document.cookie;
			var cookie_pos = allcookies.indexOf(cookie_name);
			// 如果找到了索引，就代表cookie存在，反之，就说明不存在。
			if (cookie_pos != -1) {
				// 把cookie_pos放在值的开始，只要给值加1即可。
				cookie_pos += cookie_name.length + 1;
				var cookie_end = allcookies.indexOf(";", cookie_pos);
				if (cookie_end == -1) {
					cookie_end = allcookies.length;
				}
				var value = unescape(allcookies.substring(cookie_pos, cookie_end));
			}
			return value;
		}

		$.changeTip = function(th){
			if(th.id=="userLoginPwd"){
				if(th.value=='' || th.value.length==0){
					$("#userShowPwd").css('display','block');
					$("#userLoginPwd").css('display','none');
				}
			}
			else{
				$("#userLoginPwd").css('display','block');
				$("#userShowPwd").css('display','none');
				$("#userLoginPwd").focus();
			}
		};
		
		var time = 500;
		var count = 0;
		var interval;
		$.loginProcessing = function(){
			
			count++;
			if(count % 4 == 1){
				$("#submitbutton").innerHTML = "验证中.";
				document.getElementById("submitbutton").innerHTML = "验证中.";
			}
			if(count % 4 == 2){
				document.getElementById("submitbutton").innerHTML = "验证中..";
			}
			if(count % 4 == 3){
				document.getElementById("submitbutton").innerHTML = "验证中...";
			}
			if(count % 4 == 4){
				document.getElementById("submitbutton").innerHTML = "验证中....";
			}
		}
		
		$.loginCheck = function(){
			document.getElementById("submitbutton").innerHTML = "验证中";
			console.log("。。。。。。。。");
			console.log("Time------->"+time);
			//$.loginProcessing();
			interval = setInterval("$.loginProcessing()",time);
			//$.loginProcessing();
			var options = {
					type : 'post',
					dateType : 'text',
					url : '../user/loginCheck.action',
					success : function(msg){
						msg = msg.replace(/(^\s*)/,"");
						msg = msg.replace(/(\s*$)/,"");
						//var mark3 = msg.split(",");
						//var state = mark3[0];
						//var yy = mark3[1];
						console.log(msg);
						if(msg == 'PASS'){
							clearTimeout(interval);
							alert("登陆成功");
							//window.location.href = "../user/redirectIndex.action";
							window.location.href = "./userIndex.html";
						}
						else{
							clearTimeout(interval);
							$("#loginButton").val("登  录");
							alert("用户名或密码错误");
							window.location.href="./UserLogin.html";
							
						}
					}
			};
			//clearTimeout(interval);
			$("#opForm").ajaxSubmit(options);
		}
		function userOn(){
			if(document.getElementById("login1").style.display=="none"){
				
				document.getElementById("login1").style.display="";
				document.getElementById("login2").style.display="none";
			}
		}
		function comOn(){
			if(document.getElementById("login2").style.display=="none"){
				document.getElementById("login2").style.display="";
					document.getElementById("login1").style.display="none";
			}
		}
		$.changeTip2 = function(th){
			if(th.id=="truePwd"){
				if(th.value=='' || th.value.length==0){
					$("#userShowPwd2").css('display','block');
					$("#truePwd").css('display','none');
				}
			}
			else{
				$("#truePwd").css('display','block');
				$("#userShowPwd2").css('display','none');
				$("#truePwd").focus();
			}
		};
		
		function SetPwdAndChk2(){
			var comlogin=document.getElementById("userDTO.companyManName").value;
			var options = {
					type : 'post',
					dateType : 'text',
					url : '../company/CompanyCheck.action',
					success : function(msg){
						msg = msg.replace(/(^\s*)/,"");
						msg = msg.replace(/(\s*$)/,"");
						//var mark3 = msg.split(",");
						//var state = mark3[0];
						//var yy = mark3[1];
						console.log(msg);
						if(msg == 'PASS'){
					//		clearTimeout(interval);
							alert("登陆成功");
							//window.location.href = "../user/redirectIndex.action";
							sessionStorage.setItem("comLogin",comlogin);
							window.location.href = "./CompanyAllJob.html";
						}
						else{
						//	clearTimeout(interval);
						//	$("#loginButton").val("登  录");
							alert("用户名或密码错误");
							window.location.href="./UserLogin.html";
							
						}
					}
			};
			//clearTimeout(interval);
			$("#opForm2").ajaxSubmit(options);
			//window.location.href="http://localhost:8080/jsp/system/userIndex.html"; 
		}
	</script>
</body>
</html>